#include <stdio.h>
#include <string.h>

typedef struct
{
	char ch;
	char code[10];
}character;

character tt[30]={'A',".-",'B',"-...",'C',"-.-.",'D',"-..",'E',".",'F',"..-.",'G',"--.",
				'H',"....",'I',"..",'J',".---",'K',"-.-",'L',".-..",'M',"--",'N',"-.",
				'O',"---",'P',".--.",'Q',"--.-",'R',".-.",'S',"...",'T',"-",
						  'U',"..-",'V',"...-" ,'W',".--",'X',"-..-",'Y',"-.--",'Z',"--..",
						  '_',"..--",',',".-.-",'.',"---.",'?',"----" }; // 0 - 29

char in_str[120];
char mid_str[500];
char to_str[120];
char length[120];
char temp[10];


int main()
{
	int n, i, len, j, icase=0;
	scanf("%d", &n);
	while (n-->0)
	{
		scanf("%s", in_str);
		
		memset(length, 0, sizeof(length));
		memset(mid_str, 0, sizeof(mid_str));
		memset(to_str, 0, sizeof(to_str));

		len = strlen(in_str);
		for (i=0; i<len; ++i)
		{
			for (j=0; j<=29; ++j)
				if (in_str[i]==tt[j].ch)
					break;
			strcat(mid_str, tt[j].code);
			length[i]=strlen(tt[j].code);
		}
		int site=0;
		for (i=len-1; i>=0; --i)
		{
			len = length[i];
			strncpy(temp, mid_str+site, len);
			temp[len] = 0;
			site += len;
			for (j=0; j<=29; j++)
				if (strcmp(temp, tt[j].code)==0)
					break;
			to_str[++to_str[0]]=tt[j].ch;
		}
		printf("%d: %s\n", ++icase, to_str+1);		
		
	}


	return 0;
}